package com.charity.rest.controller.manage.system;

import com.charity.common.util.JwtUtil;
import com.charity.system.service.IMenuService;
import com.charity.system.vo.model.MenuModel;
import com.charity.system.vo.model.RouterModel;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户中心-菜单管理
 *
 */
@RestController
@RequestMapping("/manage/system/menu")
@AllArgsConstructor
public class MenuController {
    
    private final IMenuService menuService;

    @GetMapping("/getRouters")
    public List<RouterModel> getRouters() {
        return menuService.selectMenuTreeByUserId(JwtUtil.getUserId());
    }

    @PostMapping("/getTreeList")
    public List<MenuModel> getTreeList(@RequestBody MenuModel model) {
        return menuService.getTreeList(model);
    }

    @GetMapping(value = "/{id}")
    public MenuModel getMenuById(@PathVariable("id") Long id) {
        return menuService.getMenuById(id);
    }

    @PostMapping("/createMenu")
    public Long createMenu(@RequestBody MenuModel model) {
        return menuService.createMenu(model);
    }

    @PostMapping("/updateMenu")
    public void updateMenu(@RequestBody MenuModel model) {
        menuService.updateMenu(model);
    }

    @DeleteMapping("/{id}")
    public Integer deleteMenu(@PathVariable("id") Long id) {
        return menuService.deleteMenu(id);
    }
}
